import Qt 4.7
Item {
    property int value

    property int min: 0
    property int max: 999
    property int selected: 0
    property int itemWidth: intSelector.width
    property int itemHeight: intSelector.height

    id: intSelector

    clip: true

    function populate() {

        // populate previous days
        for (var i = min; i <= max; i++) {
            intModel.append({
                "value": i
            });
        }
        value = i;
    }

    Component {
        id: intSelectorComponent

        Item {
            height: itemHeight
            width: itemWidth

            MouseArea {
                anchors.fill: parent
                onClicked: intListView.currentIndex = index
            }

            Text {
                id: textItem
                font.pixelSize: applicationFontSize - 4
                text: model.value
                color: heiaLightGrey
                anchors.horizontalCenter: parent.horizontalCenter
            }
            Rectangle {
                anchors.bottom: parent.bottom
                anchors.horizontalCenter: parent.horizontalCenter
                height: 32
                width: 32
                radius: 16
                smooth: true
                color: current ? heiaFocusColorOuter : heiaLightGrey

                Rectangle {
                    anchors.horizontalCenter: parent.horizontalCenter
                    anchors.verticalCenter: parent.verticalCenter
                    height: parent.height - heiaBorderWidth
                    width: parent.width - heiaBorderWidth
                    radius: 16
                    smooth: true
                    color: current ? heiaFocusColorInner : heiaDarkGrey
                }
            }
        }
    }

    ListModel {
        id: intModel
    }

    ListView {
        width: itemWidth
        height: itemHeight
        id: intListView
        model: dateModel
        delegate: intSelectorComponent
        onCurrentIndexChanged: value = currentIndex

        Component.onCompleted: {
            populate()
            intListView.currentIndex = selected - min
            positionViewAtIndex(intListView.currentIndex, ListView.Center);
        }
        onFocusChanged: intSelector.clip = intSelector.activeFocus
    }
}
